package edu.uoc.tds.pac4.client.ss3;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JLabel;

import edu.uoc.tds.pac4.beans.EstPercentatgeAsis;
import edu.uoc.tds.pac4.common.TDSLanguageUtils;

public class JPanelTotalsPerAssistencia extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel jLabelTotals = null;
	private JLabel jLabelCapacitat = null;
	private JLabel jLabelInscrits = null; 
	private JLabel jLabelAssistents = null;
	private JLabel jLabelPerAssistents = null;
	private JLabel jLabelCapacitatResultat = null;
	private JLabel jLabelInscritsResultat = null; 
	private JLabel jLabelAssistentsResultat = null;
	private JLabel jLabelPerAssistentsResultat = null;

	/**
	 * This is the default constructor
	 */
	public JPanelTotalsPerAssistencia() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		//Etiquetes
		GridBagConstraints gbcLabelTotals = new GridBagConstraints();
		gbcLabelTotals.gridx = 0;
		gbcLabelTotals.gridy = 0;
		gbcLabelTotals.gridheight = GridBagConstraints.RELATIVE;
		gbcLabelTotals.insets = new Insets(10, 10, 0, 50);
		jLabelTotals = new JLabel();
		jLabelTotals.setText(TDSLanguageUtils
				.getMessage("Client.PantallaPorcentatgeAssistencia.Totals"));
		jLabelTotals.setForeground(Color.RED);
		Font fuente = jLabelTotals.getFont();
		jLabelTotals.setFont(new Font(fuente.getFontName(), fuente.getStyle(), 30));
		
		
		
		GridBagConstraints gbcLabelCapacitat = new GridBagConstraints();
		gbcLabelCapacitat.gridx = 1;
		gbcLabelCapacitat.gridy = 0;
		gbcLabelCapacitat.insets = new Insets(0, 0, 0, 10);
		jLabelCapacitat = new JLabel();
		gbcLabelCapacitat.anchor = GridBagConstraints.LINE_END;
		jLabelCapacitat.setText(TDSLanguageUtils
				.getMessage("Client.PantallaPorcentatgeAssistencia.Places"));
		
		GridBagConstraints gbcLabelInscrits = new GridBagConstraints();
		gbcLabelInscrits.gridx = 1;
		gbcLabelInscrits.gridy = 1;
		gbcLabelInscrits.insets = new Insets(0, 0, 0, 10);
		jLabelInscrits = new JLabel();
		gbcLabelInscrits.anchor = GridBagConstraints.LINE_END;
		jLabelInscrits.setText(TDSLanguageUtils
				.getMessage("Client.PantallaPorcentatgeAssistencia.Inscrits"));
		
		GridBagConstraints gbcLabelAssistents = new GridBagConstraints();
		gbcLabelAssistents.gridx = 1;
		gbcLabelAssistents.gridy = 2;
		gbcLabelAssistents.insets = new Insets(0, 0, 0, 10);
		jLabelAssistents = new JLabel();
		gbcLabelAssistents.anchor = GridBagConstraints.LINE_END;
		jLabelAssistents.setText(TDSLanguageUtils
				.getMessage("Client.PantallaPorcentatgeAssistencia.Assistents"));
		
		GridBagConstraints gbcLabelPerAssistents = new GridBagConstraints();
		gbcLabelPerAssistents.gridx = 1;
		gbcLabelPerAssistents.gridy = 3;
		gbcLabelPerAssistents.insets = new Insets(0, 0, 0, 10);
		jLabelPerAssistents = new JLabel();
		gbcLabelPerAssistents.anchor = GridBagConstraints.LINE_END;
		jLabelPerAssistents.setText(TDSLanguageUtils
				.getMessage("Client.PantallaPorcentatgeAssistencia.PercentatgeAssistencia"));
		
		//Resultats
		GridBagConstraints gbcLabelCapacitatResultat = new GridBagConstraints();
		gbcLabelCapacitatResultat.gridx = 2;
		gbcLabelCapacitatResultat.gridy = 0;
		jLabelCapacitatResultat = new JLabel();
		gbcLabelCapacitatResultat.anchor = GridBagConstraints.LINE_END;

		
		GridBagConstraints gbcLabelInscritsResultat = new GridBagConstraints();
		gbcLabelInscritsResultat.gridx = 2;
		gbcLabelInscritsResultat.gridy = 1;
		jLabelInscritsResultat = new JLabel();
		gbcLabelInscritsResultat.anchor = GridBagConstraints.LINE_END;

		
		GridBagConstraints gbcLabelAssistentsResultat = new GridBagConstraints();
		gbcLabelAssistentsResultat.gridx = 2;
		gbcLabelAssistentsResultat.gridy = 2;
		jLabelAssistentsResultat = new JLabel();
		gbcLabelAssistentsResultat.anchor = GridBagConstraints.LINE_END;

		
		GridBagConstraints gbcLabelPerAssistentsResultat = new GridBagConstraints();
		gbcLabelPerAssistentsResultat.gridx = 2;
		gbcLabelPerAssistentsResultat.gridy = 3;
		jLabelPerAssistentsResultat = new JLabel();
		gbcLabelPerAssistentsResultat.anchor = GridBagConstraints.LINE_END;

		
		this.setLayout(new GridBagLayout());
		this.setName("jPanelTotals");
		this.add(jLabelTotals, gbcLabelTotals);
		this.add(jLabelCapacitat, gbcLabelCapacitat);
		this.add(jLabelInscrits, gbcLabelInscrits);
		this.add(jLabelAssistents, gbcLabelAssistents);
		this.add(jLabelPerAssistents, gbcLabelPerAssistents);
		this.add(jLabelCapacitatResultat, gbcLabelCapacitatResultat);
		this.add(jLabelInscritsResultat, gbcLabelInscritsResultat);
		this.add(jLabelAssistentsResultat, gbcLabelAssistentsResultat);
		this.add(jLabelPerAssistentsResultat, gbcLabelPerAssistentsResultat);
	}

	public void drawTotals(Vector<EstPercentatgeAsis> currentLlistat)
	{
		int places = 0;
		int inscrits = 0;
		int assistents = 0;
		int perAssistencia = 0;
		int contador = 0;
		// actualitza totals
		Iterator<EstPercentatgeAsis> it = currentLlistat.iterator();
		while (it.hasNext()) {
			EstPercentatgeAsis estPercentatgeAsis = it.next();
			places = places + estPercentatgeAsis.getPlaces();
			inscrits = inscrits + estPercentatgeAsis.getInscrits();
			assistents = assistents + estPercentatgeAsis.getAssistents();
			perAssistencia = perAssistencia + estPercentatgeAsis.getPercenAssistencia();
			contador++;
		}
		perAssistencia = perAssistencia / contador;
		jLabelCapacitatResultat.setText(Integer.toString(places));
		jLabelInscritsResultat.setText(Integer.toString(inscrits));
		jLabelAssistentsResultat.setText(Integer.toString(assistents));
		jLabelPerAssistentsResultat.setText(Integer.toString(perAssistencia)+"%");
	}
	
}
